package com.zh.web.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 删除枚举类
 */
@Getter
public enum Deletion {
    NOT_DELETED((short) 0, "未删除"),
    IS_DELETED((short) 1, "已删除");
    @EnumValue
    @JsonValue
    private final Short code;
    private final String desc;
    @JsonCreator
    public static Status fromValue(Object value) {
        if (value instanceof Short) {
            Short code = (Short) value;
            for (Status status : Status.values()) {
                if (status.getCode().equals(code)) {
                    return status;
                }
            }
        } else if (value instanceof String) {
            String name = (String) value;
            for (Status status : Status.values()) {
                if (status.name().equalsIgnoreCase(name)) {
                    return status;
                }
            }
        }
        throw new IllegalArgumentException("Invalid status value: " + value);
    }
    Deletion(Short code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据状态码获取对应的枚举对象
    public static Status fromCode(int code) {
        for (Status status : Status.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid status code: " + code);
    }

    // 根据状态描述获取对应的枚举对象
    public static Status fromDesc(String description) {
        for (Status status : Status.values()) {
            if (status.getDesc().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid status description: " + description);
    }

}
